package com.class05.servlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/servletA")

@SuppressWarnings("all")  // 抑制警告信息
public class ServletA extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
//        往请求域中添加数据
        req.setAttribute("name", "zhangsan");
//   往session域中添加数据
        HttpSession session = req.getSession();
        session.setAttribute("gender", "male");
//        往运用域中添加数据
        ServletContext servletContext = this.getServletContext();
        servletContext.setAttribute("age", 18);
//        请求转发
//        req.getRequestDispatcher("/servletB").forward(req, resp);



    }
}
